<style type="text/css">
.robot p {margin:0}
body,html,#mainpage,#sendbox{width: 100%;height: 100%;background: #eee;}
.robot .con{position: relative;width: 100%;height: 100%;}
.robot .con .con-head{position: absolute;width: 100%;left: 0;top: 0;height: 78px;background:#F4F7F9;border-bottom:#DBDBDB solid 0.025rem;z-index: 9999; }
.robot .con .con-head .clear-btn{position: absolute; width: 64px;height: 64px;text-align: center;line-height: 64px; border: 0.025rem solid #00a3f0; border-radius: 0.075rem;font-size: 0.4rem;color: #00a3f0;right: 0.3rem;top: 1.35rem;cursor: pointer;}
.robot .con .head-l{float: left;width: 48px;height: 48px;border-radius: 1rem; margin:10px 0 0 10px;}
.robot .con .head-r{float: left;margin-left: 18px;}
.robot .con .head-r .p1{color: #333;font-size:0.7rem;padding:1.28rem 0 0.4rem;  }
.robot .con .head-r .p2{color: #999;font-size:0.6rem;white-space: nowrap; text-overflow: ellipsis;overflow: hidden; }
#sendbox {-webkit-box-orient: vertical;-webkit-flex-direction: column;-moz-flex-direction: column;-ms-flex-direction: column;-o-flex-direction: column;flex-direction: column;}
#sendbox .chat-main{-webkit-box-flex: 1;-moz-box-flex: 1;-webkit-flex: 1;-ms-flex: 1;flex: 1;width: 100%;font-size: 0.65rem;overflow-x: hidden;-webkit-overflow-scrolling: touch;background: #eee;display: block;}
#sendbox .chat-main .chatlog(padding: 0.2rem;width:100%)
#sendbox .talk-box{overflow: hidden;}
#sendbox .talk-wrap{-webkit-box-flex: 1;-moz-box-flex: 1;-webkit-flex: 1;-ms-flex: 1;flex: 1;width: 100%;font-size: 0.28rem;overflow-x: hidden;overflow: auto; -webkit-overflow-scrolling: touch;background: #eee;}
#sendbox .l,#sendbox .r{margin:0.3rem; width:100%}
#sendbox .r .pic{float: right;width: 2rem;height: 2rem;border-radius: 0.2rem; margin-left:0.65rem;margin-right: 1.3rem;background: url('{{tomedia(pagedata.member.logo) || '../core/resource/images/gw-wx.png'}}') no-repeat;background-size: 100% 100%;}
#sendbox .l .pic{float: left;width: 1.8rem;height: 1.8rem;border-radius: 0.2rem; margin-left:0.65rem;margin-right: 0.65rem;background: url('{{tomedia(pagedata.getmember.logo) || '../core/resource/images/noavatar.gif'}}') no-repeat;background-size: 100% 100%;}
#sendbox .text{text-align: left;line-height: 1rem; padding: 0.4rem;font-size:0.7rem;background: #F5F5F7;border-radius: 0.2rem;color: #333;width: auto;max-width:10.25rem;  }
#sendbox .r .text{float: right;background: #00a3f0;color: #fff;margin-left: 0; }
#sendbox .l .text{float: left;background: #fff;margin-left:0}
#sendbox .textimg{text-align: left;line-height: 0.7rem; font-size:0.7rem;border-radius: 0.2rem;color: #333;width: auto;max-width:5rem;  }
#sendbox .r .textimg{float: right;color: #fff;margin-left: 0; }
#sendbox .l .textimg{float: left;margin-left:0}
#sendbox .logtime{text-align:center;font-size: 0.65rem;width:7.6rem;margin: 0.6rem auto 0;color: #fff;background: #ccc;border-radius: 0.2rem;}
#sendbox .loadmore{font-size:0.28rem;color:#999;text-align:center;height:1.2rem;line-height:1.2rem;}
#chat-foot{height: 2.5rem;background: #F5F5F7;width: 100%;border-top: #EBEBEB solid 1px;padding: 0.4rem 0.2rem;z-index:11}
#chat-foot span {line-height:1.3rem;font-size:1.4rem;}
#chat-foot .inp{background: #F5F5F7;float: left; display: block;color: #333;text-indent: 0.6rem;line-height:1.4rem}
#chat-foot input{border:none;border-bottom: 1px solid #EBEBEB;}
#chat-foot .sub-btn{width:2.5rem;text-align:center;float: right;background: #00a3f0;color: #fff;border-radius: 0.2rem;margin:0 0.1rem 0.2rem 0}
#chat-foot .showaudio{width:80%;border: 1px solid #EBEBEB;border-radius: 0.1rem;text-align:center;margin-left:0.2rem;padding:0.1rem 2rem;}
.icongroup{background:#F5F5F7;border-top:#EBEBEB solid 1px;padding:0.2rem 0.2rem 0 0.2rem;width:100%;height:3.4rem;}
.icongroup .flex .item{width:3.2rem;height:2.6rem;}
.icongroup .flex .item .icon-border{height:2.2rem;width:2.4rem;margin:0 auto;padding:0.3rem;border-radius:0.35rem;border:solid 1px #DCDCDE;background:#fff;text-align:center;}
.icongroup .flex .item .icon-border .icon{height:1.5rem;line-height:1.5rem;font-size:1.56rem;color:#999;}
.icongroup .flex .item .title{height:0.8rem;line-height:0.8rem;font-size:0.45rem;color:#999;text-align:center;}
.chat-audio {position: fixed;z-index: 12;left: 30%;width:40%;top: 30%;font-size: 0.65rem;color: #fff;background: #000;opacity: 0.7;border-radius: 0.15rem;text-align:center;padding:0.2rem;}
.chat-audio .recording{font-size:2rem;height:0.7rem;}
.unread {width: 10px; height: 10px;color: red;border-radius: 50%;display: block;float: left;}
.kefu-playon img{width:0.8rem;height:0.65rem}
/* 小屏幕 */
.geechat-mainrap{position: absolute;width: 100%;height: 100%;left: 0;top: 0;background-color: rgba(0,0,0,0.5);z-index: 99999;}
.geet-con{position: absolute;width: 8rem;height: 1.6rem;bottom:2rem;left: 4rem;}
.shengbo{
	background: url(../core/resource/images/audioplaying.gif) no-repeat
}
.fui-content {
	position: absolute;
	display: block;
	width: 100%;
	height:100%!important; 
	overflow: auto;
	-webkit-overflow-scrolling: touch;
	padding-bottom:0
}
.chatlog {
	min-height:100%!important; 
	display: box;
    display: -webkit-box;
    display: -moz-box;
    display: -ms-flexbox;
    display: -webkit-flex;
    display: flex;
    -webkit-box-orient: horizontal;
    -webkit-flex-direction: row;
    -moz-flex-direction: row;
    -ms-flex-direction: row;
    -o-flex-direction: row;
    flex-direction: column-reverse;
	overflow-x:Hidden；
	overflow-y:auto;
}
.fui-cell {
	position: relative;
	display: -webkit-box;
	display: -webkit-flex;
	display: -ms-flexbox;
	display: flex;
	-webkit-box-align: center;
	-webkit-align-items: center;
	-ms-flex-align: center;
	align-items: center;
	-moz-transition-duration: 300ms;
	-webkit-transition-duration: 300ms;
	transition-duration: 300ms;
	-webkit-transition-property: background-color;
	transition-property: background-color;
	line-height: 1;
}
.fui-cell .text{font-size:0.8rem;line-height:1.2rem}
.fui-cell .icon{font-size:1.6rem}
.fui-cell-group .fui-cell {line-height:1.7;height:1.6rem}
</style>
<div class="fui-page" style="z-index: 10;">
<div class="fui-content" style="max-width:680px;margin:auto;">
<div class="fe-floatback right" style="left:0.2rem">
	<a ng-click="access_json('/onehome/')">
		<i class="icon icon-back"></i>
	</a>
</div>
<div class="geechat-mainrap" style="display: none;"><div id="geet" class="geet-con"></div></div>
<div id="sendbox" class="flex">
	<div class="chat-main flex" id="svposttext">
			<div ng-show="loading" class='infinite-loading'><span class='fui-preloader'></span><span style="margin-left:1.5rem"> 正在加载...</span></div>
			<div class="chatlog">
			</div>
	</div>
	<div id="chat-foot" class="flex" id="content_type text">
			<div class="fui-cell-group" style="background:none;margin-top:0;width:100%">
				<div class="fui-cell" style="padding:0;">
					<div class="fui-cell-info">
						<div class="fui-cell" style="padding:0">
							<div class="fui-cell-icon" style="width:auto;height:1.2rem"><span class="audio icon jinyunicon icon-seeraudio l-f" style="width:1.6rem"></span></div>
							<span class="keyboard icon jinyunicon icon-keyboard hide l-f" style="font-size:1.55rem;width:1.6rem"></span>
							<div class="fui-cell-info"><input class="inp" style="width:100%" type="text" id="contentvalue" placeholder="请输入咨询内容..."></input></div>
							<span class="showaudio hide" style="font-size:0.8rem;">按住 说话</span>
						</div>
					</div>
				
					<div class="fui-cell-remark noremark" style="margin-left:0.5rem;margin-top:0.1rem;width:auto;">
						<!--<span class="icno jinyunicon icon-biaoqing"></span>-->
						<span class="sub-btn" ng-click="submitform()" style="font-size:0.65rem;margin-right:0.2rem">发送</span>
						<span class="jiamore icon jinyunicon icon-jia r-f" style="font-size:1.26rem;margin-right:0.2rem"></span>
					</div>
				</div>
			</div>
	</div>
	<div class="icongroup hide">
		<div class="flex">
						<div href="javascript:;" id="uppic" class="item" ng-if="pagedata.openid">
							<div class="icon-border">
								<i class="icon jinyunicon icon-pic"></i>
							</div>
							<div class="title">上传图片</div>
						</div>
						<div href="javascript:;" ng-click="pagedata.upfile()" class="item">
							<div class="icon-border">
								<i class="icon jinyunicon icon-exl"></i>
							</div>
							<div class="title">上传文件</div>
						</div>
						<div href="javascript:;" onclick="$('#showqr').modal();" class="item" ng-if="pagedata.kefu.showqr">
							<div class="icon-border">
								<i class="icon jinyunicon icon-qrcode"></i>
							</div>
							<div class="title">客服微信</div>
						</div>
						<div ng-if="pagedata.myiskefu!=1" href="javascript:;" onclick="$('#upcomment').modal();" class="item">
							<div class="icon-border">
								<i class="icon jinyunicon icon-haoping"></i>
							</div>
							<div class="title">客服评价</div>
						</div>
						<div href="javascript:;" ng-click="pagedata.showfastmsg=true;" class="item">
							<div class="icon-border">
								<i class="icon jinyunicon icon-zhifeiji"></i>
							</div>
							<div class="title">快捷回复</div>
						</div>
		</div>
	</div>
</div>
</div>
</div>
<div id="showqr"  class="modal fade" tabindex="-1" style="z-index:99999;display:none;">
		<div class="modal-dialog"  style="width:100%">
			<div class="modal-content" style="background:#fafafa">
				<div class="wap-qrcode-container">
					<button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button>
					<p class="example1">{{pagedata.getmember.name}}</p>
					<div class="wap-qrcode-image">
						<img ng-src="{{tomedia(pagedata.getmember.kefuqr) || '../core/resource/images/nopic.jpg'}}"/>
					</div>
					<p class="example1">长按二维码关注</p>
				</div>
			</div>
		</div>
	</div>
	<div id="upcomment"  class="modal fade" tabindex="-1" style="z-index:99999;display:none;">
		<div class="modal-dialog" style="top:20%">
			<div class="modal-content" style="background:#fafafa">
				<div class="fui-line" style="width:6rem;margin:0.5rem auto 0 auto">
					<div class="text text-danger" style="background-color:#fafafa" >评价</div>
				</div>
				<div class="weui_cells weui_cells_radio" style="padding:0.5rem">
					<div class="fui-cell-label" style="margin-right:0.8rem;float:left;margin-bottom:0.2rem">
						<input type="radio" class="fui fui-radio fui-radio-danger verify-radio" name="radio2" ng-click="pagedata.upcommenttype = 0" value="0"> 好评
					</div>
					<div class="fui-cell-label" style="margin-right:0.8rem;float:left;margin-bottom:0.2rem">
						<input type="radio" class="fui fui-radio fui-radio-danger verify-radio" name="radio2" ng-click="pagedata.upcommenttype =1" value="1"> 中评
					</div>
					<div class="fui-cell-label" style="margin-right:0.8rem;float:left;margin-bottom:0.2rem">
						<input type="radio" class="fui fui-radio fui-radio-danger verify-radio" name="radio2" ng-click="pagedata.upcommenttype =2" value="2"> 差评
					</div>
				</div>
				<div class="weui_cells weui_cells_form">
					<div class="weui_cell">
						<div class="weui_cell_bd weui_cell_primary">
							<textarea id="upcommentmsg" class="weui_textarea" placeholder="说点什么吧..." rows="2"></textarea>
							<div class="weui_textarea_counter"><span>0</span>/200</div>
						</div>
					</div>
				</div>
				<div class="modal-footer">
					<div class="mod-check" href="javascript:"  id="upcommentsubmit" aria-hidden="true" data-dismiss="modal">确认</div>
				</div>
			</div>
		</div>
	</div>
	<div ng-if="pagedata.showfastmsg" class="popup">
		<div class="popup-body">
			<div class="popup-bottom">
			<i class="closed icon icon-cuowu" ng-click="pagedata.showfastmsg=false"></i>
				<div class="fui-line" style="width:6rem;margin:0.5rem auto 0 auto">
					<div class="text text-danger" style="background-color:#fafafa" >快捷回复</div>
				</div>
				<div class="fui-cell-group noborder col-1" style="height:16rem;ovrflow-y:scroll;background: #ffffff;padding-bottom:15px;">
					<a ng-repeat="item in pagedata.fastmsg track by $index" aria-hidden="true" data-dismiss="modal" class="fui-cell" href="javascript:;" ng-click="submitform(item)">
						{{item}}
					</a>
				</div>
				<div class="content-empty" ng-show="!pagedata.fastmsg || pagedata.fastmsg.length == 0 ">
					  <i class="icon jinyunicon icon-cry" style="width: 6rem;margin-bottom: 0.5rem;"></i><br/><p style="color: #999;font-size: .75rem">暂时没有快捷方式！</p>
				</div>
			</div>
		</div>
	</div>
	<!--弹出录音-->
	<div class="chat-audio hide">
		<i class="recording icon jinyunicon icon-shengbo1"></i>
		<p>正在录音中...</p>
	</div>
	<div id="followewm" class="modal fade" tabindex="-1" style="z-index:99999;display:none;">
		<div class="modal-dialog" style="width:96%;top:2%;left:2%" aria-hidden="true" data-dismiss="modal">
			<div class="images-modal">
			<div class="mod-image" style="">
				<img style="width:100%;" ng-src="{{tomedia(pagedata.textimg)}}"/>
			</div>
			</div>
		</div>
	</div>
<audio id="openvoice" controls preload="auto" style="display:none;">
	<source src="../core/resource/images/message.mp3"></source>
</audio>
<script type="text/javascript">
scope.pagedata.is_backpage=false
//滚动加载
scope.scroll(function(){
	scope.loading = true;  //状态标记
	scope.$evalAsync();
	setTimeout('getlist()',500);
},true,'svposttext');
function followewm(textimg){
	scope.pagedata.textimg = textimg;
	scope.$apply();
	$('#followewm').modal();
}
var images = {
	localIds: [],
};
var voice = {
	localId: '',
	serverId: ''
};
scope.loading = true;  //状态标记
getlist(1);
$('#svposttext').animate({scrollTop:100000},300);
//获取HTML
scope.pagedata.get_html=function(data){
	//console.log('data');console.log(data);
	scope.get_data(function(res){
		var htmlmsg=res.html
		if(htmlmsg){
			$('#svposttext').append(htmlmsg).animate({scrollTop:100000},300);
		}
	},'','/chat/gethtml/id='+data.id+'&chatid='+data.chatid);
}
require(['jquery'], function($){
	$('#content_type').hide();
	$('#text').show();
	toggle('text');
	//录音按钮
	$(".audio").on("click",function(){
		$(".audio,.inp").addClass("hide");
		$(".keyboard,.showaudio").removeClass("hide");
	});
	$(".keyboard").on("click",function(){
		$(".keyboard,.showaudio").addClass("hide");
		$(".audio,.inp").removeClass("hide");
	});
	$(".jiamore").on("click",function(){
		$(".icongroup").removeClass("hide");
	});
	$(".inp").on("click",function(){
		$(".icongroup").addClass("hide");
	});
	$(".showaudio").on("click",function(){
		$(".chat-audio").removeClass("hide");
	});
	$(".showaudio").on("touchstart",function(event){
		event.preventDefault();
		$(".showaudio").text("松开  结束");
		START = new Date().getTime();
		recordTimer = setTimeout(function(){
			wx.startRecord({
				success: function(){
					localStorage.rainAllowRecord = 'true';
					$(".chat-audio").removeClass('hide');
					var num=59;
					name = setInterval(function() {
						num--;
						if(num==0){          
							clearInterval(name);
							END = new Date().getTime();
							wx.stopRecord({
								success: function (res) {
									voice.localId = res.localId;
									$('.chat-audio').addClass("hide");
									var audiotime = (END - START);
									uploadVoice(audiotime);
								},
								fail: function (res) {
									alert("停止录音动作发生异常", "forbidden");
								}
							});
							$(".showaudio").text('按住  说话');
						}
					}, 1000);
				},
				cancel: function () {
					alert("您拒绝授权录音", "cancel");
				}
			});
		},300);
	});

	//松手结束录音
	$(".showaudio").on('touchend', function(event){
		event.preventDefault();
		END = new Date().getTime();
		$(".showaudio").text('按住  说话');
		$('.chat-audio').addClass("hide");
		if((END - START) < 1500){
			END = 0;
			START = 0;
			//小于300ms，不录音
			alert("录音时间太短", "forbidden");
			clearTimeout(recordTimer);
			wx.stopRecord();
		}else{
			wx.stopRecord({
				success: function (res) {
					voice.localId = res.localId;
					var audiotime = (END - START);
					uploadVoice(audiotime);
			    },
			    fail: function (res) {
					alert("停止录音动作发生异常", "forbidden");
			    }
			});
		}
	});
	$("#upcommentsubmit").click(function(){
			var params = {
					'plugin':'jy_kefu',
					'action':'upcomment',
					'data':{
						getmid:scope.pagedata.getmember.id,
						commenttype:scope.pagedata.upcommenttype,
						msg:$("#upcommentmsg").val(),
					},
					'callback':function(data){
							console.log(data)
							if(data.error !=1){
								$('.icongroup').addClass('hide');
								alert('评价成功！');
							}else{
								alert(data.msg);
							}
					}
			}
			scope.post_json(params);
	});
	$('#uppic').click(function(){
		scope.tool.up_file('image',function(res){
			addchat(res,4,0);
		})
	});
});
scope.pagedata.upfile=function(){
	scope.up_file(function(res){
		addchat(res,7,0);
	},'','other');
}
var page = 1;
scope.pagedata.isnodata=false;
function getlist(){
	if(scope.pagedata.isnodata){
		scope.loading = false;
		scope.$evalAsync();
		return false;
	}
		var params = {
					'plugin':'jy_kefu',
					'action':'chat',
					'op':'list',
					'query':'page='+page+'&chatid='+scope.pagedata.chatid,
					'data':{},
					'callback':function(data){
							console.log('page');console.log(page)
							if(data.error !=1){
								$('.chatlog').append(data.html);
								if(page >1){
									$("#svposttext").animate({scrollTop:0},300);
								}
								if(!data.html){
									scope.pagedata.isnodata=true;
								}
								page++;
								scope.loading = false;
								scope.pagedata.lastid=data.lastid;
								scope.$evalAsync();
							}else{
								scope.message(data.msg,'error');
							}
					}
		}
		scope.post_json(params);
}
//上传录音
function uploadVoice(audiotime){
		//调用微信的上传录音接口把本地录音先上传到微信的服务器
		//不过，微信只保留3天，而我们需要长期保存，我们需要把资源从微信服务器下载到自己的服务器
		wx.uploadVoice({
			localId: voice.localId, // 需要上传的音频的本地ID，由stopRecord接口获得
			isShowProgressTips: 1, // 默认为1，显示进度提示
			success: function (res) {
				//把录音在微信服务器上的id（res.serverId）发送到自己的服务器供下载。
				console.log(res);
				addchat(res.serverId,3,audiotime);
			}
		});
}
function toggle(type) {
	var curtype = type;
			$('#content_type').hide();
			$("#" + curtype).show();

			buildRequest(type);
			$('#receive').text('');
			//$('#svposttext').hide();
			$('#svtext').hide();
			$('#svurlbox').hide();
			$('#sendxml').attr('readonly', 'readonly');
			if(type == 'other') {
				$('#sendxml').removeAttr('readonly');
			}
}
function getxml(xmlstring){
			var xmlobject = null;
			try{
				if(window.ActiveXObject){
					xmlobject =new ActiveXObject("Microsoft.XMLDOM");
					xmlobject.async="false";
					xmlobject.loadXML(xmlstring);
				}else{// 用于 Mozilla, Firefox, Opera, 等浏览器的代码：
					var parser=new DOMParser();
					xmlobject =parser.parseFromString(xmlstring,"text/xml");
				}
			}catch(e){alert("您的浏览器不支持");}
			return xmlobject;
}
function buildRequest(type) {
			var $sendbox = $('#sendbox');
			$('span.time', $sendbox).show();
			$('div.mediaImg', $sendbox).show();
			$('div.mediaContent', $sendbox).show();
			$('div.mediaFooterbox', $sendbox).show();
			var time = Math.round(new Date().getTime()/1000);
			xml = 	"<xml>\n"+
				"<ToUserName><![CDATA["+$('#touser').val()+"]]></ToUserName>\n"+
				"<FromUserName><![CDATA["+$('#fromuser').val()+"]]></FromUserName>\n"+
				"<CreateTime>"+time+"</CreateTime>\n";
			if (type == 'text') {
				xml += "<MsgType><![CDATA[text]]></MsgType>\n";
				xml += "<Content><![CDATA["+$('#contentvalue').val()+"]]></Content>\n";
				$('#svpostinfo').text($('#contentvalue').val());
			}
			xml +=  "<MsgId>1234567890123456</MsgId>\n"+
				"</xml>";
			if(type == 'other') {
				xml = $('#sendxml').val();
			}
			$('#sendxml').val(xml);
}
function addchat(msg,type,audiotime){
			$('#process').hide();
			buildRequest(type);
			$('#svtext').hide();$('#svurlbox').hide();$('#svinfolist').hide();
			$('div.mediaFooterbox', $('#sendbox')).show();
			var params = {
					'plugin':'jy_kefu',
					'action':'addchat',
					'data':{
							getmid:scope.pagedata.getmember.id,
							chatid:scope.pagedata.chatid,
							msg:msg,
							type:type,
							audiotime:audiotime,
					},
					'callback':function(data){
						if(data.error !=1){
							$('#svposttext').show();
							$('#svposttext').append(data.htmlmsg).animate({scrollTop:100000},300);
							$('#contentvalue').val('');
							scope.pagedata.lastid=data.id;
						}else{
							alert(data.msg);
						}
					}
			}
			scope.post_json(params);	
}
scope.submitform=function(msg,type) {
	//苹果手机键盘归让页面归位
	type=type?type:1
	window.scroll(0,0); //让页面归位
			$('#process').hide();
			buildRequest(type);
			$('#svtext').hide();$('#svurlbox').hide();$('#svinfolist').hide();
			$('div.mediaFooterbox', $('#sendbox')).show();
			var text = $('#contentvalue').val();
			text =msg?msg:text;
			console.log(text);
			var addchat = 'addchat';
			var getmid = scope.pagedata.getmember.id;
			if(!getmid){
				getmid = 0;
				addchat = 'addrobotchat';
			}
			var params = {
					'plugin':'jy_kefu',
					'action':addchat,
					'data':{
							getmid:getmid,
							chatid:scope.pagedata.chatid,
							msg:text,
							type:1,
					},
					'callback':function(data){
						if(data.error !=1){
							$('#svposttext').show();
							var htmlmsg = '<div class="r clearfix"><img class="pic"/><p class="text">'+text+'</p></div>';
							if(data.msg){
								htmlmsg += '<div class="l clearfix"><img class="pic"/><p class="text">'+data.msg+'</p></div>';
							}
							$('#svposttext').append(htmlmsg).animate({scrollTop:100000},300);
							$('#contentvalue').val('');
							scope.pagedata.lastid=data.id;
						}else{
							scope.message(data.msg,'error');
						}
					}
			}
			scope.post_json(params);	
}
function upwelcometext() {
	//socketlog(scope.pagedata.welcomelogid,scope.pagedata.chatid);
}
if(scope.pagedata.welcomelogid){
	upwelcometext()
}
function nl2br(str, is_xhtml) {
			var breakTag = (is_xhtml || typeof is_xhtml === 'undefined') ? '<br ' + '/>' : '<br>'; // Adjust comment to avoid issue on phpjs.org display
			return (str + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1' + breakTag + '$2');
}
function playaudio(serverid,obj,id){
		wx.downloadVoice({
			serverId: serverid,
			success: function (res) {
				console.log(res)
				wx.playVoice({
					localId: res.localId,
				});
				scope.post_json('jy_kefu/upchatlog/',{id:id},function(red){});
			},
			fail: function (res) {
				scope.message(res.errMsg,'error');
			}
		});
}
</script>
<script type="text/javascript">
wx.ready(function () {
	wx.hideOptionMenu();
	wx.onVoicePlayEnd({
		success: function (res) {
		}
	});
	wx.onVoiceRecordEnd({
		complete: function (res) {
			voice.localId = res.localId;
			$.alert('录音时间已超过一分钟');
		}
	});
});
scope.pagedata.openvoice=function(type){
	var voicetime = 0;
    var openvoice;
	for(var i = 1;i<=100;i++){
		clearInterval(i);
	}
	//return false;
	if(type){
		 openvoice = setInterval(() => {
			if(scope.page.action!='onechat'){
				clearInterval(openvoice);
				return false;
			}
			if(!scope.pagedata.lastid){
				if(scope.pagedata.list && scope.pagedata.list[0]){
					scope.pagedata.lastid=scope.pagedata.list[0].id;
				}
			}
			scope.get('jy_kefu/index/getnewlog/is_worker=1&chatid='+scope.pagedata.chatid+'&lastid='+scope.pagedata.lastid,function(res){
				//console.log(res);
				if(res.log){
					scope.pagedata.lastid=res.log.id;
					var htmlmsg=res.html
					if(htmlmsg){
						$('#svposttext').append(htmlmsg).animate({scrollTop:100000},300);
					}
				}
			});
		}, 2000);
	}
}
scope.pagedata.openvoice(1);
</script>